//
//  TTCouponViewCell.m
//  TaoTuo
//
//  Created by admin on 2019/9/29.
//  Copyright © 2019 admin. All rights reserved.
//

#import "TTCouponViewCell.h"

@interface TTCouponViewCell ()

@property (nonatomic, strong) UIImageView *bgImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UILabel *infoLabel;
@property (nonatomic, strong) UIImageView *flagImageView;

@property (nonatomic, strong) TTCouponModel *model;

@end

@implementation TTCouponViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self setupSubviews];
        
    }
    
    return self;
}

- (void)setModel:(TTCouponModel *)model isInvalid:(BOOL)isInvalid
{
    self.model = model;
    
    self.titleLabel.text = model.Name;
    self.timeLabel.text = [NSString stringWithFormat:@"%@~%@", model.BeginTime, model.EndTime];
    
    self.infoLabel.text = model.Descriptions;
    
    NSString *money = [NSString stringWithFormat:@"￥%@", model.CouponMoney];
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:money];
    [attr addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:35]} range:[money rangeOfString:model.CouponMoney]];
    self.priceLabel.attributedText = attr;
    
    if (isInvalid) {
        // 无效
        self.priceLabel.textColor = UIColorHex(999999);
        self.flagImageView.hidden = NO;
    } else {
        self.priceLabel.textColor = UIColorHex(8954FB);
        self.flagImageView.hidden = YES;
    }
    
}

- (void)setupSubviews
{
    UIImage *image = [UIImage imageNamed:@"youhiuquan_kuang"];
    image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(image.size.height * 0.88, 100, image.size.height * 0.1, 100) resizingMode:UIImageResizingModeStretch];
    _bgImageView = [[UIImageView alloc] initWithImage:image];
    [self.contentView addSubview:_bgImageView];
    [_bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(5);
        make.left.mas_equalTo(10);
        make.right.equalTo(self.contentView).mas_offset(-10);
        make.bottom.equalTo(self.contentView).mas_offset(-5);
    }];
    
    _titleLabel = [UILabel labelWithTitle:@"" color:UIColorHex(333333) fontSize:15];
    [self.bgImageView addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(20);
        make.left.mas_equalTo(12);
    }];
    
    _timeLabel = [UILabel labelWithTitle:@"" color:UIColorHex(666666) fontSize:13];
    [self.bgImageView addSubview:_timeLabel];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).mas_offset(5);
        make.left.equalTo(self.titleLabel);
    }];
    
    _priceLabel = [UILabel labelWithTitle:@"" color:UIColorHex(8954FB) fontSize:18];
    [self.bgImageView addSubview:_priceLabel];
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel);
        make.right.equalTo(self.bgImageView).mas_offset(-15);
    }];
    
    _infoLabel = [UILabel labelWithTitle:@"" color:UIColorHex(999999) fontSize:11];
    _infoLabel.numberOfLines = 0;
    [self.bgImageView addSubview:_infoLabel];
    [_infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timeLabel.mas_bottom).mas_offset(30);
        make.left.equalTo(self.titleLabel);
        make.bottom.equalTo(self.bgImageView).mas_offset(-8);
        make.right.equalTo(self.bgImageView).mas_offset(-10);
    }];
    
    _flagImageView = [[UIImageView alloc] init];
    _flagImageView.image = [UIImage imageNamed:@"yiguoqi"];
    _flagImageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.bgImageView addSubview:_flagImageView];
    [_flagImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.priceLabel);
        make.width.height.mas_equalTo(50);
        make.centerY.equalTo(self.bgImageView);
    }];
    
}


@end
